package com.ruoyi.web.dorm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.dorm.entity.DormListEntity;
import com.ruoyi.web.dorm.entity.RepairRegistrationEntity;
import com.ruoyi.web.dorm.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dorm/repair")
public class RepairController extends BaseController {

    @Autowired
    private RepairService repairService;

    /**
     * 查询宿舍维修信息
     * @param repairRegistrationEntity
     * @return
     */
    @GetMapping("/getRepairList")
    public TableDataInfo getRepairList(RepairRegistrationEntity repairRegistrationEntity){
        startPage();
        return getDataTable(repairService.getRepairList(repairRegistrationEntity));
    }

    /**
     * 添加宿舍维修信息
     * @param repairRegistrationEntity
     * @return
     */
    @PostMapping("/addRepairList")
    public AjaxResult addRepairList(@RequestBody RepairRegistrationEntity repairRegistrationEntity ){
        return toAjax(repairService.addRepairList(repairRegistrationEntity));
    }

    /**
     * 更新宿舍报修信息
     * @param repairRegistrationEntity
     * @return
     */
    @PostMapping("/updateRepair")
    public AjaxResult updateRepair(@RequestBody RepairRegistrationEntity repairRegistrationEntity){
        return toAjax(repairService.updateRepair(repairRegistrationEntity));
    }

    /**
     * 删除宿舍报修信息
     * @param id
     * @return
     */
    @DeleteMapping("/delRepair")
    public AjaxResult delRepair(Long id){
        return toAjax(repairService.delRepair(id));
    }



    /**
     * 查询宿舍报修信息导出信息
     * @param repairRegistrationEntity
     * @return
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response,RepairRegistrationEntity repairRegistrationEntity){
        List<RepairRegistrationEntity> list = repairService.getRepairList(repairRegistrationEntity);
        ExcelUtil<RepairRegistrationEntity> util = new ExcelUtil<>(RepairRegistrationEntity.class);
        util.exportExcel(response,list,"宿舍报修信息数据");
    }
}
